package ar.com.utn.openqsb.lip.core;

import org.apache.commons.math.linear.RealVector;
import org.apache.commons.math.linear.RealVectorImpl;

public class Constraint
{

	public static enum Relation
	{
		LE("<="), EQ("="), GE(">=");

		private String symbol;

		Relation(String symbol)
		{
			this.symbol = symbol;
		}

		public Relation opposite()
		{
			if ("<=".equalsIgnoreCase(symbol))
			{
				return GE;
			} else if (">=".equalsIgnoreCase(symbol))
			{
				return LE;
			}
			return this;
		}

		@Override
		public String toString()
		{
			return symbol;
		}

	}

	private RealVector coefficients;

	private Relation relation;

	private double rightValue;

	public Constraint(int numVar)
	{
		coefficients = new RealVectorImpl(new double[numVar]);
		this.relation = Relation.EQ;
		this.rightValue = 0.0;
	}

	public Constraint(RealVector coefficients, Relation relation, double rightValue)
	{
		this.coefficients = coefficients;
		this.relation = relation;
		this.rightValue = rightValue;
	}

	public void setCoefficient(final int index, final double coefficient)
	{
		coefficients.setEntry(index, coefficient);
		System.out.println("Set " + index + " to " + coefficient);
	}

	public RealVector getCoefficients()
	{
		return coefficients;
	}

	public void setRelation(final Relation relation)
	{
		this.relation = relation;
		System.out.println("Set " + relation);
	}

	public Relation getRelation()
	{
		return relation;
	}

	public void setRightValue(double rightValue)
	{
		this.rightValue = rightValue;
		System.out.println("Set " + rightValue);
	}

	public double getRightValue()
	{
		return rightValue;
	}

}
